package com.ruoyi.web.controller.workSafetyStandardization.rule;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workSafetyStandardization.domain.Limit;
import com.ruoyi.workSafetyStandardization.service.ILimitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评分-参评限制Controller
 *
 * @author pengjie
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/secure/securerule/limit")
public class LimitController extends BaseController
{
    @Autowired
    private ILimitService limitService;

    /**
     * 查询评分-参评限制列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Limit limit,@Param("pageSize") String pageSize,@Param("pageNum") String pageNum)
    {
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<Limit> list = limitService.selectLimitList(limit);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:list')")
    @GetMapping("/queryAll")
    public AjaxResult queryAll()
    {
        Limit  limit=new Limit();
        System.out.println(limit);
        return success(limitService.selectLimitList(limit));
    }

    /**
     * 导出评分-参评限制列表
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:export')")
    @Log(title = "评分-参评限制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Limit limit)
    {
        List<Limit> list = limitService.selectLimitList(limit);
        ExcelUtil<Limit> util = new ExcelUtil<Limit>(Limit.class);
        util.exportExcel(response, list, "评分-参评限制数据");
    }

    /**
     * 获取评分-参评限制详细信息
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:query')")
    @GetMapping(value = "/{limitId}")
    public AjaxResult getInfo(@PathVariable("limitId") String limitId)
    {
        return success(limitService.selectLimitByLimitId(limitId));
    }

    /**
     * 新增评分-参评限制
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:add')")
    @Log(title = "评分-参评限制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Limit limit)
    {
        limit.setLimitId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(limitService.insertLimit(limit));
    }

    /**
     * 修改评分-参评限制
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:edit')")
    @Log(title = "评分-参评限制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Limit limit)
    {
        return toAjax(limitService.updateLimit(limit));
    }

    /**
     * 删除评分-参评限制
     */
    @PreAuthorize("@ss.hasPermi('workSafetyStandardization:limit:remove')")
    @Log(title = "评分-参评限制", businessType = BusinessType.DELETE)
	@GetMapping("/delete")
    public AjaxResult remove(@Param("limitId") String limitId)
    {
        String[] limitIds={limitId};
        return toAjax(limitService.deleteLimitByLimitIds(limitIds));
    }
}
